var url;
var projectId = null;
var detailId = null;
var temp_data = null;

$(function() {
	$("#gmtRefundTr").hide();
	$("#msgSPAN").hide();
	$("#gmtRefund").datepicker({
		showButtonPanel: true
	});
	$('#gmtRefund').datepicker("option", "dateFormat", "yy-mm" );
	$('#gmtRefund').datepicker('option', 'changeMonth', true);
	
	
	$("#type .typeLabel").bind('click',function(){
		var date = $("#gmtRefund").val();
		if (date == "" || date == undefined){
			//return false;
		}
		var type = $(this).attr("data-type");
		getDetail(type, date);
	});
	$("#gmtRefund").bind('change',function(){
		var type=$('#type').find(':checked').val();
		if (type == "" || type == undefined){
			return false;
		}
		var date = $("#gmtRefund").val();
		getDetail(type, date);
	});
	
	
	//初始化====================================
	$("#type").buttonset();
	$("#dataGird").flexigrid({
		url: "/project/newproject/selectForPage.json",
		colModel : [
		    {display: "ID", name : "id", width : 90, sortable : true,hide: true},
	        {display: "项目名称", name : "name", width : 400, sortable : true},
	        {display: "项目编码", name : "code", width : 90, sortable : true},
	        {display: "承接部门", name : "deptName", width : 90, sortable : true},
			{display: "合同额(元)", name : "contractValue", width : 90, sortable : true,process:formatCost},
			{display: "工资/奖金系数(%)", name : "wageCoefficient", width : 110, sortable : true, hide: false,process:formatPercent},
			{display: "类型", name : "type", width : 90, sortable : true,process:formatType},
			{display: "DETAILID", name : "detailId", width : 90, sortable : true, hide: true},
			{display: "外业地勘(元)", name : "geosurveyCost", width : 90, sortable : true,process:formatCost},
			{display: "外业测量(元)", name : "surveyCost", width : 90, sortable : true,process:formatCost},
			{display: "内业费用(元)", name : "designCost", width : 90, sortable : true,process:formatCost},
			{display: "外业其他(元)", name : "otherCost", width : 90, sortable : true,process:formatCost},
			{display: "OTHERDETAIL", name : "otherDetail", width : 90, sortable : true, hide: true},
			//otherCost geosurveyCost surveyCost designCost
			{display: "GEOSURVEYDETAIL", name : "geosurveyDetail", width : 90, sortable : true, hide: true},
			{display: "SURVEYDETAIL", name : "surveyDetail", width : 90, sortable : true, hide: true},
			{display: "DESIGNDETAIL", name : "designDetail", width : 90, sortable : true, hide: true},
			{display: "外业承包(元)", name : "outsideCost", width : 90, sortable : true,process:formatCost},
			{display: "会务费用(元)", name : "conferenceCost", width : 90, sortable : true,process:formatCost},
			{display: "分院产值(元)", name : "branchValue", width : 90, sortable : true,process:formatCost},
			{display: "已完成(%)", name : "completedRate", width : 90, sortable : true,process:formatPercent},
			{display: "预(核)算完成额(元)", name : "budgetcalcCplValue", width : 90, sortable : true,process:formatCost},
			{display: "创建时间", name : "gmtCreate", width : 120, sortable : true, hide: true},
			{display: "创建人", name : "creator", width : 120, sortable : true, hide: true},
			{display: "修改时间", name : "gmtCreate", width : 120, sortable : true, hide: true},
			{display: "修改人", name : "modifier", width : 120, sortable : true, hide: true}
			]
    }); 
	
	$('#projectDialog').dialog({
		resizable: false,
		autoOpen: false,
		width: 650,
		height: 500,
		modal: true
	});
		
	$( "#dialogConfirm" ).dialog({
		resizable: false,
		autoOpen: false,
		height:180,
		modal: true,
		buttons: {
			"确认删除": function() {
				MZ.ajaxShowMsg({
					url : "/project/project/delete",
					data:{id:$("#dataGird").flexigrid().getRowValue(2)},
					success:function(data){
						MZ.closeDialog("dialogConfirm");
						MZ.searchGird("searchForm","dataGird");
					},
					failure:function(data){
						MZ.closeDialog("dialogConfirm");
					}
				});
			},
			"取消": function() {
				MZ.closeDialog("dialogConfirm");
			}
		}
	});
	
	$('#addotherCost').bind('click',function(){
//		var liSize = $("#othercostField li").length;
//		var otherCost=$('#othercostLI1').clone(true);
//		otherCost.insertBefore('#addOtherCostLi');
//		otherCost.attr("id","othercostLI"+liSize)
//		$("#othercostLI"+liSize+" input[name='otherCost']").val("");
//		$('#othercostField li a[name="delOther"]').each(function(i){
//			$("#othercostLI"+(i+1)+" a[name='delOther']").hide();
//		});
//		$("#othercostLI"+liSize+" a[name='delOther']").show();
//		otherCost.show();
		addBtnEvent("otherCost");
	});
	$('#otherCostField a[name="delOther"]').bind('click',function(){
//		var liSize = $("#othercostField li").length-1;
//		//update totalCurrency
//		var otherCostVal = $("#othercostLI"+liSize+" input[name='otherCost']").val();
//		otherCostVal = $.trim(otherCostVal) * 1;
//		if(otherCostVal != ""){
//			if($("#totalCurrencySPAN").text() != ""){
//				var totalVal = ($("#totalCurrencySPAN").text() * 1) - otherCostVal;
//				totalVal = MZ.toDecimal(totalVal, MZ.CURRENCY_ROUND);
//				$("#totalCurrencySPAN").text(totalVal);
//			}
//		}
//		var otherCost=$(this).parents("li");
//		otherCost.remove();
//		liSize = $("#othercostField li").length-1;
//		if(liSize != 1){
//			$("#othercostLI"+liSize+" a[name='delOther']").show();
//		}
		delBtnEvent("otherCost", $(this));
	});
	
	$('#addgeosurveyCost').bind('click',function(){
		addBtnEvent("geosurveyCost");
	});
	$('#geosurveyCostField a[name="delOther"]').bind('click',function(){
		delBtnEvent("geosurveyCost", $(this));
	});
	$('#addsurveyCost').bind('click',function(){
		addBtnEvent("surveyCost");
	});
	$('#surveyCostField a[name="delOther"]').bind('click',function(){
		delBtnEvent("surveyCost", $(this));
	});
	$('#adddesignCost').bind('click',function(){
		addBtnEvent("designCost");
	});
	$('#designCostField a[name="delOther"]').bind('click',function(){
		delBtnEvent("designCost", $(this));
	});
	$('#calc_branch_value_href').bind('click',function(){
		var contractValue = $("#contractValue").val() * 1;
		var res = eachOtherCost("otherCost");
		otherCost = res[0] * 1;
		res = eachOtherCost("geosurveyCost");
		geosurveyCost = res[0] * 1;
		res = eachOtherCost("surveyCost");
		surveyCost = res[0] * 1;
		res = eachOtherCost("designCost");
		designCost = res[0] * 1;
		var outsideCost = $("#outsideCost").val() * 1;
		var conferenceCost = $("#conferenceCost").val() * 1;
		var branchValue = contractValue - otherCost - geosurveyCost - surveyCost - designCost - outsideCost - conferenceCost;
		$("#branchValue").val(branchValue);
	});
	
	
	function addBtnEvent(btnname){
		var liSize = $("#"+btnname+"Field li").length;
		var otherCost=$('#'+btnname+'LI1').clone(true);
		otherCost.insertBefore('#add'+btnname+'Li');
		otherCost.attr("id",btnname+"LI"+liSize)
		$("#"+btnname+"LI"+liSize+" input[name='"+btnname+"']").val("");
		$('#'+btnname+'Field li a[name="delOther"]').each(function(i){
			$("#"+btnname+"LI"+(i+1)+" a[name='delOther']").hide();
		});
		$("#"+btnname+"LI"+liSize+" a[name='delOther']").show();
		otherCost.show();
	}
	function delBtnEvent(btnname, btnObj){
		var liSize = $("#"+btnname+"Field li").length-1;
		//update totalCurrency
		var otherCostVal = $("#"+btnname+"LI"+liSize+" input[name='"+btnname+"']").val();
		otherCostVal = $.trim(otherCostVal) * 1;
		if(otherCostVal != ""){
			if($("#totalCurrencySPAN").text() != ""){
				var totalVal = ($("#totalCurrencySPAN").text() * 1) - otherCostVal;
				totalVal = MZ.toDecimal(totalVal, MZ.CURRENCY_ROUND);
				$("#totalCurrencySPAN").text(totalVal);
			}
		}
		var otherCost=btnObj.parents("li");
		otherCost.remove();
		liSize = $("#"+btnname+"Field li").length-1;
		if(liSize != 1){
			$("#"+btnname+"LI"+liSize+" a[name='delOther']").show();
		}
	}
	
	//绑定金额输入框keyup事件
	//当输入框数量more时，需要采用total-old+new更新total值
	//不宜再全局运算
	$("#projectForm input.currency-type").keyup(function(event){ 
		//console.log("oldVal in key up: %d", oldVal);
		var reg = /^-?\d+\.{0,}\d{0,}$/;
		if(!reg.test($(this).val())){
			$(this).val("");
		}
	});
	$("#contractValue").keyup(function(event){ 
		var cpVal = $("#completedRate").val();
		if(cpVal == ""){
			return false;
		}else{
			cpVal = cpVal * 1;
			$("#budgetcalcCplValue").val(cpVal*($(this).val()*1)/100);
		}
	});
	$("#completedRate").keyup(function(event){ 
		if ($(this).val()*1 > 100){
			MZ.showMsg("已完成值百分比范围(0-100)%!");
			$(this).val(0)
			return false;
		}
		var contractValue = $("#contractValue").val();
		if(contractValue == ""){
			MZ.showMsg("合同额不能为空!");
			return false;
		}
		var date = $("#gmtRefund").val();
		if (date == "" || date == undefined){
			$("#budgetcalcCplValue").val(contractValue*($(this).val()*1)/100);
		}else{
			setPercentVal(temp_data, $(this).val()*1)
		}
		
	});
	
	
	//事件监控====================================
	//重置表单
	$("#clearButton").bind("click",function(){
		MZ.reset("searchForm");
	});
	
	//查询数据
	$("#searchButton").bind("click",function(){
		MZ.searchGird("searchForm","dataGird");
	});
	
	//打开新增数据对话框
	$("#add").bind("click", function(){
		$("#gmtRefundTr").hide();
		$("#name").attr("readonly",false);
		$("#ui-dialog-title-projectDialog").text("新增项目");
		MZ.clearForm("projectForm");
		$("#resetBtn").show();
		$('#type1').click();
		isupdate=false;
		MZ.openDialog("projectDialog");
	});
	
	//打开修改数据对话框
	$("#update").bind("click", function(){
		MZ.clearForm("projectForm");
		$("#gmtRefundTr").show();
		$("#msgSPAN").show();
		var rowVals = $("#dataGird").flexigrid().getRowValues();
		if(rowVals.length == 1){
			var rowVal = rowVals[0];
			temp_data = rowVal;
			isupdate=true;
			//填充数据
			emptyOtherDetail();
			loadCost(rowVal);
			$("#ui-dialog-title-projectDialog").text("项目预(核)算提交");
			$("#msgSPAN").html("<strong>提示 </strong>统计期为空时,为项目总预(核)算.");
			$("#resetBtn").hide();
			MZ.openDialog("projectDialog");
		}else{
			MZ.showMsg("请选择需要提交预(核)算的项目!");
			return false;
		}
	});
	
	//删除数据
	$("#delete").bind("click", function(){
		if ($("#dataGird").flexigrid().getRowValue(2).length<=0){
			MZ.showMsg("请选择要删除的数据");
			return ;
		}
		$("#dialogConfirm").text("该操作将删除选定的用户信息，确定这样做?");
		MZ.openDialog("dialogConfirm");
	});
	
	function eachOtherCost(btnname){
		var res = new Array();
		var costDataArr = new Array();
		var dictName = "";
		var liId = null;
		var cost = null;
		var otherCost = 0;
		$("#"+btnname+"Field select[name='"+btnname+"']").each(function(i){
			if($(this).val() != null && $(this).val() != ""){
				liId = $(this).parents("li").attr("id");
				cost = $("#"+liId+" input[name='"+btnname+"']").val() * 1;
				otherCost += cost * 1;
				dictName = $(this).find("option:selected").text();
				if(otherCost > 0){
					costDataArr.push("{'cost':"+cost+",'id':"+$(this).val()+",'name':'"+dictName+"'}");
				}
			}
		});
		res.push(otherCost);
		res.push(costDataArr);
		return res;
	}
	
	//提交数据
	$("#submitBtn").bind("click", function(){
		var params=$('#projectForm').serializeObject();
		var type=$('#type').find(':checked').val();
		params['type']=type;
		if (isupdate){
			url="/project/newproject/updateById";
			params['projectId']=projectId;
			params['detailId']=detailId;
		}else{
			url="/project/newproject/insert";
		}
		
		for(var key in params){
			if(key.indexOf("Cost") != -1 || key.indexOf("Value") != -1){
				params[key] = MZ.toDecimal(params[key] * MZ.CURRENCY_PRECISION, MZ.CURRENCY_ROUND);
			}
		}
		var res = eachOtherCost("otherCost");
		params["otherCost"] = res[0] * MZ.CURRENCY_PRECISION;
		if(res[1].toString() !=""){
			params["otherDetail"] = "["+res[1].toString()+"]";
		}
		res = eachOtherCost("geosurveyCost");
		params["geosurveyCost"] = res[0] * MZ.CURRENCY_PRECISION;
		if(res[1].toString() !=""){
			params["geosurveyDetail"] = "["+res[1].toString()+"]";
		}
		res = eachOtherCost("surveyCost");
		params["surveyCost"] = res[0] * MZ.CURRENCY_PRECISION;
		if(res[1].toString() !=""){
			params["surveyDetail"] = "["+res[1].toString()+"]";
		}
		res = eachOtherCost("designCost");
		params["designCost"] = res[0] * MZ.CURRENCY_PRECISION;
		if(res[1].toString() !=""){
			params["designDetail"] = "["+res[1].toString()+"]";
		}
		
		if (!validata(params)){
			return false;
		}
		params = extractParams(params);
		//$.toJSON
		//alert($.toJSON(params));
		MZ.ajaxShowMsg({
			url : url,
			data:"pro=" + $.toJSON(params["pro"]) +"&detail="+$.toJSON(params["detail"]),
			success:function(){
				MZ.closeDialog("projectDialog");
				MZ.searchGird("searchForm","dataGird");	
			}
		});
	});
	
	//取消
	$("#cancelBtn").bind("click", function(){
		MZ.closeDialog("projectDialog");
	});
	//重置
	$("#resetBtn").bind("click", function(){
		MZ.reset("projectForm");
		$('#type1').click();
	});
	
});

function getDetail(type, date){
	var params = {"pid":projectId,"type":type, "date": date};
	$.ajax({
		url : "/project/newproject/selectDetail",
		type : "post",
		data : params,
		beforeSend : function() {
		},
		success : function(result) {
			if(result.succeed){
				$("#msgSPAN").html("<strong>提示 </strong>当前统计期:"+date+",修改模式.");
				$("#inputTable input.currency-type").val("");
				emptyOtherDetail();
				setDetail(result.data);
			}else{
				$("#msgSPAN").html("<strong>提示 </strong>当前统计期:"+date+",新增模式.");
				//reset detail id
				detailId = "";
				emptyOtherDetail();
				$("#inputTable input.currency-type").val("");
				setDetail(result.data);
			}
		},
		error: function(result){
			//MZ.showMsg(result);
		}
	});
}

function onSelectRow(tr){
	//
}

function loadOtherCost(otherDetail, btnname){
	if($.trim(otherDetail) != ""){
		otherDetail = eval( "(" + otherDetail + ")" );
		var obj = null;
		for(var i in otherDetail){
			obj = otherDetail[i];
			if(i == 0){
				$("#"+btnname+"LI1 select[name='"+btnname+"']").val(obj["id"]);
				$("#"+btnname+"LI1 input[name='"+btnname+"']").val(obj["cost"]);
			}else{
				var liSize = $("#"+btnname+"Field li").length;
				var otherCost=$('#'+btnname+'LI1').clone(true);
				otherCost.insertBefore('#add'+btnname+'Li');
				otherCost.attr("id",btnname+"LI"+liSize)
				$("#"+btnname+"LI"+liSize+" select[name='"+btnname+"']").val(obj["id"]);
				$("#"+btnname+"LI"+liSize+" input[name='"+btnname+"']").val(obj["cost"]);
				otherCost.show();
			}
		} 
		$('#'+btnname+'Field li a[name="delOther"]').each(function(i){
			$("#"+btnname+"LI"+(i+1)+" a[name='delOther']").hide();
		});
		var liSize = $("#"+btnname+"Field li").length - 1;
		$("#"+btnname+"LI"+liSize+" a[name='delOther']").show();
	}
}

function loadOtherCostPercent(otherDetail, btnname, per_val){
	if($.trim(otherDetail) != ""){
		otherDetail = eval( "(" + otherDetail + ")" );
		var obj = null;
		for(var i in otherDetail){
			obj = otherDetail[i];
			if(i == 0){
				$("#"+btnname+"LI1 select[name='"+btnname+"']").val(obj["id"]);
				$("#"+btnname+"LI1 input[name='"+btnname+"']").val(obj["cost"] * per_val/100);
			}else{
				var liSize = $("#"+btnname+"Field li").length;
				var otherCost=$('#'+btnname+'LI1').clone(true);
				otherCost.insertBefore('#add'+btnname+'Li');
				otherCost.attr("id",btnname+"LI"+liSize)
				$("#"+btnname+"LI"+liSize+" select[name='"+btnname+"']").val(obj["id"]);
				$("#"+btnname+"LI"+liSize+" input[name='"+btnname+"']").val(obj["cost"] * per_val/100);
				otherCost.show();
			}
		} 
		$('#'+btnname+'Field li a[name="delOther"]').each(function(i){
			$("#"+btnname+"LI"+(i+1)+" a[name='delOther']").hide();
		});
		var liSize = $("#"+btnname+"Field li").length - 1;
		$("#"+btnname+"LI"+liSize+" a[name='delOther']").show();
	}
}

function setDetail(detailObj){
	//set detail id
	detailId = detailObj["id"];
	$("#inputTable input.currency-type").each(function(i){
		costId = (this.id);
		if(costId != "completedRate"){
			$("#"+costId).val(MZ.toDecimal(detailObj[costId]/MZ.CURRENCY_PRECISION , MZ.CURRENCY_ROUND));
		}else{
			$("#"+costId).val(detailObj[costId]);
		}
	});
	//load other cost
	//otherCost geosurveyCost surveyCost designCost
	var otherDetail = detailObj['otherDetail'];
	loadOtherCost(otherDetail, "otherCost");
	otherDetail = detailObj['geosurveyDetail'];
	loadOtherCost(otherDetail, "geosurveyCost");
	otherDetail = detailObj['surveyDetail'];
	loadOtherCost(otherDetail, "surveyCost");
	otherDetail = detailObj['designDetail'];
	loadOtherCost(otherDetail, "designCost");
}

function validata(data){
	var flag = true;
	if (MZ.isBlank(data.name)){
		MZ.showMsg("项目名称不能为空!");
		return false;
	}
	if (MZ.isBlank(data.code)){
		MZ.showMsg("项目编号不能为空!");
		return false;
	}
	if (MZ.isBlank(data.deptName)){
		MZ.showMsg("项目承接部门不能为空!");
		return false;
	}
	if (MZ.isBlank(data.type)){
		MZ.showMsg("请选择控制类型!");
		return false;
	}
	//
	if (MZ.isBlank(data.contractValue)){
		MZ.showMsg("请输入合同额!");
		return false;
	}
	if (!MZ.isNumber(data.contractValue)){
		MZ.showMsg("合同额必须是数字");
		return false;
	}
	//
	if (MZ.isBlank(data.wageCoefficient)){
		MZ.showMsg("请输入工资/奖金系数!");
		return false;
	}else{
		if(data.wageCoefficient>100){
			MZ.showMsg("请输入工资/奖金系数!范围(0-100%)");
			return false;
		}
	}
	//otherCost
	//otherCost geosurveyCost surveyCost designCost
	flag = validotherCost("otherCost");
	if( !flag ){
		return false;
	}
	flag = validotherCost("geosurveyCost");
	if( !flag ){
		return false;
	}
	flag = validotherCost("surveyCost");
	if( !flag ){
		return false;
	}
	flag = validotherCost("designCost");
	if( !flag ){
		return false;
	}
	return flag;
}

function validotherCost(btnname){
	//otherCost
	var flag = true;
	var liId = null;
	var cost = null;
	$("#"+btnname+"Field select[name='"+btnname+"']").each(function(i){
		liId = $(this).parents("li").attr("id");
		cost = $("#"+liId+" input[name='"+btnname+"']").val();
		if($(this).val() == null || $(this).val() == ""){
			if(i != 0){
				MZ.showMsg("未选择有效的其他报销项!");
				flag = false;
			}else{
				if(cost != ""){
					MZ.showMsg("未选择有效的其他报销项!");
					flag = false;
				}
			}
		}else{
			if(cost == ""){
				MZ.showMsg("未输入有效的其他报销项!");
				flag = false;
			}
		}
	});
	return flag;
}

function formatCost(tdDiv, pid){
	var cost = $(tdDiv).text();
	if(cost == "0"){
		return "";
	}
	return MZ.toDecimal(cost/MZ.CURRENCY_PRECISION , MZ.CURRENCY_ROUND);
}
function formatPercent(tdDiv, pid){
	var val = $(tdDiv).text();
	if(val != ""){
		//val += "%";
	}
	return val;
}

function formatType(tdDiv, pid){
	var type = $(tdDiv).text();
	if (type==1){
		return "预算";
	}else if(type=2){
		return "核算";
	}else{
		return "未知";
	}
}
function extractParams(param){
	var projectData = {};
	var detailData = {};
	projectData["name"] = param.name;
	projectData["code"] = param.code;
	projectData["deptName"] = param.deptName;
	projectData["contractValue"] = param.contractValue;
	projectData["wageCoefficient"] = param.wageCoefficient;
	
	detailData["type"] = param.type;
	detailData["gmtRefund"] = param.gmtRefund;
	detailData["geosurveyCost"] = param.geosurveyCost;
	detailData["surveyCost"] = param.surveyCost;
	detailData["designCost"] = param.designCost;
	detailData["outsideCost"] = param.outsideCost;
	detailData["conferenceCost"] = param.conferenceCost;
	detailData["branchValue"] = param.branchValue;
	detailData["completedRate"] = param.completedRate;
	detailData["budgetcalcCplValue"] = param.budgetcalcCplValue;
	detailData["otherCost"] = param.otherCost;
	detailData["otherDetail"] = param.otherDetail;
	detailData["geosurveyCost"] = param.geosurveyCost;
	detailData["geosurveyDetail"] = param.geosurveyDetail;
	detailData["surveyCost"] = param.surveyCost;
	detailData["surveyDetail"] = param.surveyDetail;
	detailData["designCost"] = param.designCost;
	detailData["designDetail"] = param.designDetail;
	//otherCost geosurveyCost surveyCost designCost
	if(param['projectId'] != "" && param['projectId'] != undefined){
		projectData["id"] = param['projectId']
	}
	if(param['detailId'] != "" && param['detailId'] != undefined){
		detailData["id"] = param['detailId']
	}
	return {"pro":projectData, "detail":detailData};
}

function setPercentVal(jsonData, per_val){
	delete jsonData['completedRate'];
	for(var key in jsonData){
		$("#"+key).val((jsonData[key] * per_val)/100);
	}
	//load other cost
	//otherCost geosurveyCost surveyCost designCost
	var otherDetail = jsonData['otherDetail'];
	loadOtherCostPercent(otherDetail, "otherCost", per_val);
	otherDetail = jsonData['geosurveyDetail'];
	loadOtherCostPercent(otherDetail, "geosurveyCost", per_val);
	otherDetail = jsonData['surveyDetail'];
	loadOtherCostPercent(otherDetail, "surveyCost", per_val);
	otherDetail = jsonData['designDetail'];
	loadOtherCostPercent(otherDetail, "designCost", per_val);
}

//LOAD COST INFO 2 FORM 4 UPDATE
function loadCost(jsonData){
	//costTable
	//set project id and name
	projectId = jsonData["id"];
	detailId = jsonData["detailId"];
	$("#name").val(jsonData["name"]);
	$("#name").attr("readonly",true); 
	for(var key in jsonData){
		$("#"+key).val(jsonData[key]);
	}
	if(jsonData["type"]=="预算"){
		$('#type1').click();
	}else if (jsonData["type"]=="核算"){
		$('#type2').click();
	}
	//load other cost
	//otherCost geosurveyCost surveyCost designCost
	var otherDetail = jsonData['otherDetail'];
	loadOtherCost(otherDetail, "otherCost");
	otherDetail = jsonData['geosurveyDetail'];
	loadOtherCost(otherDetail, "geosurveyCost");
	otherDetail = jsonData['surveyDetail'];
	loadOtherCost(otherDetail, "surveyCost");
	otherDetail = jsonData['designDetail'];
	loadOtherCost(otherDetail, "designCost");
}

function readonlyForm(formId, flag){
	if(flag){
		$("#"+formId+" input").attr("readonly",true);
	}else{
		$("#"+formId+" input").attr("readonly",false);
	}
}

function emptyOtherDetail(){
	var liSize = $("#otherCostField li").length;
	for(i = 2; i<liSize; i++){
		$('#otherCostLI'+i).remove();
	}
	//geosurveyCost surveyCost designCost
	var liSize = $("#geosurveyCostField li").length;
	for(i = 2; i<liSize; i++){
		$('#geosurveyCostLI'+i).remove();
	}
	var liSize = $("#surveyCostField li").length;
	for(i = 2; i<liSize; i++){
		$('#surveyCostLI'+i).remove();
	}
	var liSize = $("#designCostField li").length;
	for(i = 2; i<liSize; i++){
		$('#designCostLI'+i).remove();
	}
}